package patterns.filter;

import java.util.List;

/**
 * Created by lenovo on 2016/11/24 0024.
 * 具体标准实现类
 */
public class FilterOr implements IFilter {
    //双重筛选标准共同作用
    private IFilter filter1;//标准1
    private IFilter filter2;//标准2

    public FilterOr(IFilter filter1, IFilter filter2) {
        this.filter1 = filter1;
        this.filter2 = filter2;
    }

    @Override
    public List<Person> matchCriteria(List<Person> personList) {
        List<Person> firstFilterList = filter1.matchCriteria(personList);
        List<Person> secondFilterList = filter2.matchCriteria(firstFilterList);
        //筛选满足条件1或者2 的对象，这里就是把满足条件二的，放到1的结果里，返回出去
        for (Person person : secondFilterList) {
            if (!firstFilterList.contains(person)) {
                firstFilterList.add(person);
            }
        }
        return firstFilterList;
    }
}
